package com.starlinkdt.common.mapper.system;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.starlinkdt.common.domain.system.entity.TaskDispatch;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface TaskDispatchMapper extends BaseMapper<TaskDispatch> {

    int batchMarkAsSuccess(@Param("tasks") List<TaskDispatch> tasks);

    int batchMarkAsFailed(@Param("tasks") List<TaskDispatch> tasks);

    int batchMarkAsProcessing(@Param("tasks") List<TaskDispatch> tasks);

    int batchMarkAsNoHandled(@Param("tasks") List<TaskDispatch> tasks);

    int batchMarkAsPending(@Param("tasks") List<TaskDispatch> tasks);

    /**
     * 分页查询失败且可重试的任务
     */
    List<TaskDispatch> getFailedTasksForRetry(@Param("limit") int limit, @Param("offset") int offset,@Param("taskType") int taskType, @Param("businessType") String businessType, @Param("tryTimes") int tryTimes);

    /**
     * 分页查询长期处于进行中的任务
     */
    List<TaskDispatch> getProcessingTasksForRetry(@Param("limit") int limit, @Param("taskType") int taskType, @Param("businessType") String businessType);

    /**
     * 分页查询待执行的任务
     */
    List<TaskDispatch> getPendingTasks(@Param("limit") int limit, @Param("taskType") int taskType, @Param("businessType") String businessType);

    /**
     * 判断是否存在待执行的任务
     */
    int existsPendingTask(String businessId);

    /**
     * 获取最新的任务
     */
    TaskDispatch getLatestTaskByBusinessId(String businessId);

}
